#include "mode_key_handle.h"
void mode_net_handle(SYS_OPT_KEY opt)
{  
    if(OPT_MATCH_NET==opt.oepation) //判断是否是配网模式
    {
        come_to_match_network();
    }
}

SYS_OPT_KEY on_off_opt(EM_DRV_ACT key_act)
{
    SYS_OPT_KEY opt={.oepation=DRV_ACT_NONE};
    if (key_act == DRV_ACT_KEY_1S)
    {
        opt.oepation = DRV_ACT_NONE;
    }
    else if((key_act == DRV_ACT_KEY_SHORT)&&(key_act != DRV_ACT_KEY_1S))
    {
        if(app_logic_get_ssp() == SSP_POWER_OFF) //判断当前状态
        {
            opt.oepation = OPT_POWER_TURNON; //开机
        }
        else
        {
            opt.oepation = OPT_POWER_TURNOFF; //关机
        }
    }
    else if(key_act == DRV_ACT_KEY_5S) //开始配网
    {
        opt.oepation = OPT_MATCH_NET;
        LOG_INFO("match network\n");
    }
    LOG_INFO("on_off_opt %d\n",opt.oepation);
    return opt;
}

SYS_OPT_KEY mode_opt(EM_DRV_ACT key_act)
{
    SYS_OPT_KEY opt;
    if (key_act == DRV_ACT_KEY_SHORT)
    {
        if(app_logic_get_ssp() != SSP_POWER_OFF)
        {
            opt.oepation = OPT_GO_NEXT; //下一步
        }
        else
        {
            opt.oepation = OPT_INVALID; //无效操作
        }
    }
    else if(key_act == DRV_ACT_KEY_1S)
    {
        opt.oepation = OPT_INVALID; //无效操作
    }
    else
    {
        opt.oepation = OPT_INVALID;
    }
    LOG_INFO("mode_opt %d\n",opt.oepation);
    return opt;
}

SYS_OPT_KEY brightness_add_opt(EM_DRV_ACT key_act)
{
    SYS_OPT_KEY opt;
    if((app_logic_get_ssp() != SSP_POWER_OFF))
    {
        if (key_act == DRV_ACT_KEY_SHORT)
        {
            opt.oepation = OPT_GO_ADD;
        }
        else if(key_act == DRV_ACT_KEY_1S)
        {
            opt.oepation = OPT_GO_ADD_CONTINUE; 
        }
        else
        {
            opt.oepation = OPT_INVALID;
        }
    }
    else
    {
        opt.oepation = OPT_INVALID; //无效操作
    }
    return opt;
}

SYS_OPT_KEY brightness_reduce_opt(EM_DRV_ACT key_act)
{
    SYS_OPT_KEY opt;
    if((app_logic_get_ssp() != SSP_POWER_OFF))
    {
        if (key_act == DRV_ACT_KEY_SHORT)
        {
            opt.oepation = OPT_GO_REDUCE;//减小
        }
        else if(key_act == DRV_ACT_KEY_1S)
        {
            opt.oepation = OPT_GO_REDUCE_CONTINUE; //无效操作
        }
        else
        {
            opt.oepation = OPT_INVALID;
        }
    }
    else
    {
        opt.oepation = OPT_INVALID; //无效操作
    }
    LOG_INFO("brightness_reduce_opt %d\n",opt.oepation);
    return opt;
}

SYS_OPT_KEY microphone_opt(EM_DRV_ACT key_act)
{
    SYS_OPT_KEY opt;
    
    if (key_act == DRV_ACT_KEY_SHORT)
    {
        if(app_logic_get_ssp() == SSP_MODE_MIC)
        {
            opt.oepation = OPT_OUT_MIC; //退出麦克风模式
        }
        else
        {
            opt.oepation = OPT_GO_MIC; //进入麦克风模式
        }
        
    }
    else if(key_act == DRV_ACT_KEY_1S)
    {
        opt.oepation = OPT_INVALID; //无效操作
    }
    else
    {
        opt.oepation = OPT_INVALID;
    }
    LOG_INFO("microphone_opt %d\n",opt.oepation);
    return opt;
}

SYS_OPT_KEY app_logic_act_to_opt(key_act_param key_act)
{
    SYS_OPT_KEY opt;
    if(key_act.drvAct == DRV_ACT_NONE)
    {
      opt.oepation = OPT_NONE;
    }

    switch (key_act.key_num)
    {
      case 0: //开关配网键
        opt = on_off_opt(key_act.drvAct);
        break;
      case 1:  //灯带模式切换键
        opt = mode_opt(key_act.drvAct);
        break;
      case 2: //亮度减小键
        opt = brightness_reduce_opt(key_act.drvAct);
        break;
      case 3://亮度增加键
        opt = brightness_add_opt(key_act.drvAct);
        break;
      case 4: //麦克风模式切换键
         opt = microphone_opt(key_act.drvAct);
        break;
      default:
        break;
    }
    LOG_INFO("opt.oepation is %d\n",opt.oepation);
    return opt;
}
